package Code.Day2_20240919.com.dx.day02;


import java.util.Arrays;
import java.util.Scanner;

/**
 * @ClassName Test02
 * @Description 数组
 * @Author 12994
 * @Date 2024/9/19 11:33
 * @Version 1.0
 **/
public class Test02 {
    /**
     * 简单数组操作
     *
     * @param args
     */
    public static void main(String[] args) {
        double[] list = new double[6];
        for (int i = 0; i < list.length; i++) {
            list[i] = i;
        }

        // avg -> sum/length
        Scanner input = new Scanner(System.in);
        double sum = 0D;
        for (int i = 0; i < list.length; i++) {
            System.out.printf("输入第%d门成绩: ", i + 1);
            double _this_num = input.nextDouble();
            if (_this_num > 100 || _this_num < 0) {
                System.out.println("Score is illegal !!");
                break;
            }
            if (_this_num < 5) {
                System.out.println("Score is too low, skip.");
                continue;
            }
            sum += _this_num;
        }
        System.out.printf("Legal score is %.2f !\n", sum);
        // list.length != 0
        System.out.printf("Avg is %.2f !\n", sum / list.length);
        // Arrays的平均值 -> 需要注意OptionalDouble中的值是否存在->使用isPresent()
        System.out.println(Arrays.stream(list).average().getAsDouble());


        // 相同类型直接引用内存地址，且修改时不发生copy(和Python不一样)
        double[] list2 = list;
        //派生类型比较是否相等->比较是否为同一内存地址
        System.out.println(list == list2);
        System.out.println(list == list.clone());

        System.out.println(Arrays.toString(list));
        list2[5] = 100;
        System.out.println(Arrays.toString(list));
    }
}
